package chapter1.No1_8_暂停线程.c缺点_不同步;

/**
 * 数据不同步的问题
 * Created by Administrator on 2016/11/9.
 */
public class Test {
    String u = "1";
    String p = "11";
    public void doTest(String u, String p) {
        this.u = u;
        if("a".equals(Thread.currentThread().getName())) {
            System.out.println("a线程暂停");
            Thread.currentThread().suspend();
        }
        this.p = p;
    }

    public void printUP() {
        System.out.println("U="+u);
        System.out.println("P="+p);
    }

    public static void main(String[] args) throws InterruptedException {
        final Test test = new Test();

        // A
        Thread a = new Thread("a"){
            @Override
            public void run() {
                test.doTest("a", "aa");
            }
        };
        a.start();

        Thread.sleep(100);

        // B
        Thread b = new Thread() {
            @Override
            public void run() {
                test.printUP();
            }
        };
        b.start();

    }
}
